﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace FtpWorkerRole.FtpServer
{
    class CloudFtpServer
    {
        public int port { get; set; }
        private TcpListener listener;
        private Socket socket;
        private TcpClient client;
        private NetworkStream networkStream;

        public CloudFtpServer(int _port)
        {
            this.port = _port;
        }

        public void listen()
        {
            try
            {
                listener = new TcpListener(this.port);
                listener.Start();                
                Thread thread = new Thread(new ThreadStart(accept));
                thread.Start();
            }
            catch (Exception e) { }

        }

        private void accept()
        {
            while (true)
            {                
                client = listener.AcceptTcpClient();                
                if (client.Connected)
                {
                    var handler = new FtpSocketHandler();
                    handler.start(client);
                }
            }
        }


    }
}
